﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace zhihu {
    public partial class FormExport : Form {
        public FormExport() {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e) {
            List<ViewInfo> listViewInfo;
            if (rdoExportTop.Checked) {
                listViewInfo = ZhihuHelper.GetTopOfDataBase(int.Parse(txtExportTop.Text.Trim()));
            }
            else{
                listViewInfo = ZhihuHelper.GetTopOfDataBase(int.Parse(txtExportRange1.Text.Trim()), int.Parse(txtExportRange2.Text.Trim()));
            }

            SaveFileDialog sfdlg = new SaveFileDialog();
            sfdlg.InitialDirectory = Application.StartupPath;
            sfdlg.Filter = @"网页文件|*.html|所有文件|*.*";
            sfdlg.FilterIndex = 0;
            if (sfdlg.ShowDialog() == DialogResult.OK) {
                ExportHelper.Expore(sfdlg.FileName, listViewInfo);
            }
            DialogResult = DialogResult.OK;
        }

        private void RadioBtn_CheckedChanged(object sender, EventArgs e) {
            RadioButton rdo = sender as RadioButton;
            if (!rdo.Checked) return;
            switch (rdo.Tag.ToString()) {
                case "Range":
                    txtExportTop.Enabled = false;
                    txtExportRange1.Enabled = true;
                    txtExportRange2.Enabled = true;
                    break;
                case "Top":
                    txtExportRange1.Enabled = false;
                    txtExportRange2.Enabled = false;
                    txtExportTop.Enabled = true;
                    break;
                default:
                    break;
            }

        }
    }
}
